package com.xiaoma.tpo.web.activity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xiaoma.tpo.domain.ActivityType;
import com.xiaoma.tpo.service.ActivityTypeService;

@Controller
@RequestMapping("activityTypeManage")
public class ActivityTypeController {

	@Autowired
	private ActivityTypeService activityTypeService;
	
	@RequestMapping(value = "/list")
	@ResponseBody
	public Map<String, Object> getAllActivityType(Integer page, Integer rows) {
		
		Map<String, Object> result = new HashMap<String, Object>();
		List<ActivityType> list = activityTypeService.findAll(page, rows);
		result.put("rows", list);
		result.put("total", activityTypeService.findAll().size());
		return result;
	}
	
	@RequestMapping(value = "/add")
	@ResponseBody
	public Map<String, Object> add(ActivityType type) {

		Map<String, Object> result = new HashMap<String, Object>();
		try {
			type.setIsDelete(0);
			activityTypeService.saveOrUpdate(type);
			result.put("status", "SUCCESS");
		} catch (Exception e) {
			e.getStackTrace();
			result.put("status", "FAIL");
		}
		return result;
	}
	
	@RequestMapping(value = "/remove")
	@ResponseBody
	public Map<String, Object> remove(@RequestParam(value = "id") Integer id) {

		Map<String, Object> result = new HashMap<String, Object>();
		try {
			ActivityType activityType = activityTypeService.findById(id);
			activityType.setIsDelete(1);
			activityTypeService.saveOrUpdate(activityType);
			result.put("status", "SUCCESS");
		} catch (Exception e) {
			e.getStackTrace();
			result.put("status", "FAIL");
		}
		return result;
	}
}
